package LeetCode.binTree_LeetCode;
import java.lang.Math;

public class Num55 {
    public boolean isBalanced(TreeNode root) {
        if(root == null){
            return true;
        }
        if(Math.abs(height(root.left) - height(root.right)) <= 1 && isBalanced(root.left) && isBalanced(root.right)){
            return true;
        }
        return false;
    }

    private int height(TreeNode root) {
        if(root == null){
            return 0;
        }else {
            return 1 + Math.max(height(root.left) , height(root.right));
        }
    }

}
